﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.MountAndBlade.View.Scripts.PopupSceneSwitchItemSequence
// Assembly: TaleWorlds.MountAndBlade.View, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 61152EB8-513B-4D4A-8AC0-0D1465C6CF6C
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\Modules\Native\bin\Win64_Shipping_Client\TaleWorlds.MountAndBlade.View.dll

using TaleWorlds.Core;

#nullable disable
namespace TaleWorlds.MountAndBlade.View.Scripts
{
  public class PopupSceneSwitchItemSequence : PopupSceneSequence
  {
    public string InitialItem;
    public string PositiveItem;
    public string NegativeItem;
    public PopupSceneSwitchItemSequence.BodyPartIndex InitialBodyPart;
    public PopupSceneSwitchItemSequence.BodyPartIndex PositiveBodyPart;
    public PopupSceneSwitchItemSequence.BodyPartIndex NegativeBodyPart;

    public override void OnInitialState()
    {
      this.AttachItem(this.InitialItem, this.InitialBodyPart);
    }

    public override void OnPositiveState()
    {
      this.AttachItem(this.PositiveItem, this.PositiveBodyPart);
    }

    public override void OnNegativeState()
    {
      this.AttachItem(this.NegativeItem, this.NegativeBodyPart);
    }

    private EquipmentIndex StringToEquipmentIndex(PopupSceneSwitchItemSequence.BodyPartIndex part)
    {
      switch (part)
      {
        case PopupSceneSwitchItemSequence.BodyPartIndex.None:
          return EquipmentIndex.None;
        case PopupSceneSwitchItemSequence.BodyPartIndex.Weapon0:
          return EquipmentIndex.WeaponItemBeginSlot;
        case PopupSceneSwitchItemSequence.BodyPartIndex.Weapon1:
          return EquipmentIndex.Weapon1;
        case PopupSceneSwitchItemSequence.BodyPartIndex.Weapon2:
          return EquipmentIndex.Weapon2;
        case PopupSceneSwitchItemSequence.BodyPartIndex.Weapon3:
          return EquipmentIndex.Weapon3;
        case PopupSceneSwitchItemSequence.BodyPartIndex.ExtraWeaponSlot:
          return EquipmentIndex.ExtraWeaponSlot;
        case PopupSceneSwitchItemSequence.BodyPartIndex.Head:
          return EquipmentIndex.NumAllWeaponSlots;
        case PopupSceneSwitchItemSequence.BodyPartIndex.Body:
          return EquipmentIndex.Body;
        case PopupSceneSwitchItemSequence.BodyPartIndex.Leg:
          return EquipmentIndex.Leg;
        case PopupSceneSwitchItemSequence.BodyPartIndex.Gloves:
          return EquipmentIndex.Gloves;
        case PopupSceneSwitchItemSequence.BodyPartIndex.Cape:
          return EquipmentIndex.Cape;
        case PopupSceneSwitchItemSequence.BodyPartIndex.Horse:
          return EquipmentIndex.ArmorItemEndSlot;
        case PopupSceneSwitchItemSequence.BodyPartIndex.HorseHarness:
          return EquipmentIndex.HorseHarness;
        default:
          return EquipmentIndex.None;
      }
    }

    private void AttachItem(
      string itemName,
      PopupSceneSwitchItemSequence.BodyPartIndex bodyPart)
    {
      if (this._agentVisuals == null)
        return;
      EquipmentIndex equipmentIndex = this.StringToEquipmentIndex(bodyPart);
      if (equipmentIndex == EquipmentIndex.None)
        return;
      AgentVisualsData agentVisualsData = this._agentVisuals.GetCopyAgentVisualsData();
      Equipment equipment = this._agentVisuals.GetEquipment().Clone();
      if (itemName == "")
        equipment.AddEquipmentToSlotWithoutAgent(equipmentIndex, new EquipmentElement());
      else
        equipment.AddEquipmentToSlotWithoutAgent(equipmentIndex, new EquipmentElement(Game.Current.ObjectManager.GetObject<ItemObject>(itemName)));
      agentVisualsData.RightWieldedItemIndex(0).LeftWieldedItemIndex(-1).Equipment(equipment);
      this._agentVisuals.Refresh(false, agentVisualsData, false);
    }

    public enum BodyPartIndex
    {
      None,
      Weapon0,
      Weapon1,
      Weapon2,
      Weapon3,
      ExtraWeaponSlot,
      Head,
      Body,
      Leg,
      Gloves,
      Cape,
      Horse,
      HorseHarness,
    }
  }
}
